package myUserManage

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
    "github.com/flipped-aurora/gin-vue-admin/server/model/myUserManage"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
    myUserManageReq "github.com/flipped-aurora/gin-vue-admin/server/model/myUserManage/request"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
    "github.com/flipped-aurora/gin-vue-admin/server/service"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
    "github.com/flipped-aurora/gin-vue-admin/server/utils"
)

type MyUserManageApi struct {
}

var myUserService = service.ServiceGroupApp.MyUserManageServiceGroup.MyUserManageService


// CreateMyUserManage 创建MyUserManage
// @Tags MyUserManage
// @Summary 创建MyUserManage
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body myUserManage.MyUserManage true "创建MyUserManage"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /myUser/createMyUserManage [post]
func (myUserApi *MyUserManageApi) CreateMyUserManage(c *gin.Context) {
	var myUser myUserManage.MyUserManage
	err := c.ShouldBindJSON(&myUser)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
    verify := utils.Rules{
        "Gh":{utils.NotEmpty()},
    }
	if err := utils.Verify(myUser, verify); err != nil {
    		response.FailWithMessage(err.Error(), c)
    		return
    	}
	if err := myUserService.CreateMyUserManage(&myUser); err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteMyUserManage 删除MyUserManage
// @Tags MyUserManage
// @Summary 删除MyUserManage
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body myUserManage.MyUserManage true "删除MyUserManage"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /myUser/deleteMyUserManage [delete]
func (myUserApi *MyUserManageApi) DeleteMyUserManage(c *gin.Context) {
	var myUser myUserManage.MyUserManage
	err := c.ShouldBindJSON(&myUser)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := myUserService.DeleteMyUserManage(myUser); err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteMyUserManageByIds 批量删除MyUserManage
// @Tags MyUserManage
// @Summary 批量删除MyUserManage
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除MyUserManage"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /myUser/deleteMyUserManageByIds [delete]
func (myUserApi *MyUserManageApi) DeleteMyUserManageByIds(c *gin.Context) {
	var IDS request.IdsReq
    err := c.ShouldBindJSON(&IDS)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if err := myUserService.DeleteMyUserManageByIds(IDS); err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateMyUserManage 更新MyUserManage
// @Tags MyUserManage
// @Summary 更新MyUserManage
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body myUserManage.MyUserManage true "更新MyUserManage"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /myUser/updateMyUserManage [put]
func (myUserApi *MyUserManageApi) UpdateMyUserManage(c *gin.Context) {
	var myUser myUserManage.MyUserManage
	err := c.ShouldBindJSON(&myUser)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
      verify := utils.Rules{
          "Gh":{utils.NotEmpty()},
      }
    if err := utils.Verify(myUser, verify); err != nil {
      	response.FailWithMessage(err.Error(), c)
      	return
     }
	if err := myUserService.UpdateMyUserManage(myUser); err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindMyUserManage 用id查询MyUserManage
// @Tags MyUserManage
// @Summary 用id查询MyUserManage
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query myUserManage.MyUserManage true "用id查询MyUserManage"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /myUser/findMyUserManage [get]
func (myUserApi *MyUserManageApi) FindMyUserManage(c *gin.Context) {
	var myUser myUserManage.MyUserManage
	err := c.ShouldBindQuery(&myUser)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if remyUser, err := myUserService.GetMyUserManage(myUser.ID); err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"remyUser": remyUser}, c)
	}
}

// GetMyUserManageList 分页获取MyUserManage列表
// @Tags MyUserManage
// @Summary 分页获取MyUserManage列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query myUserManageReq.MyUserManageSearch true "分页获取MyUserManage列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /myUser/getMyUserManageList [get]
func (myUserApi *MyUserManageApi) GetMyUserManageList(c *gin.Context) {
	var pageInfo myUserManageReq.MyUserManageSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := myUserService.GetMyUserManageInfoList(pageInfo); err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败", c)
    } else {
        response.OkWithDetailed(response.PageResult{
            List:     list,
            Total:    total,
            Page:     pageInfo.Page,
            PageSize: pageInfo.PageSize,
        }, "获取成功", c)
    }
}
